/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Compiler.h"

#if defined(__IASMARM__) || defined(__ICCARM__)
        SECTION .mcal_text_asm_mcallib:CODE(2)
        ARM
#elif defined(__ghs__) || defined(__ghs_asm)
        .section ".mcal_text_asm_mcallib"
#else
        .section ".text"
        .arm
#endif
    ASM_PUBLIC memcpy_4bytes_aligned
/* void *memcpy_4bytes_aligned(void* dst, void* src, uint32 bytes) */
ASM_FUNCTION(memcpy_4bytes_aligned)
	push {r4-r11}
	mov r3, r0
word8_cp:
	cmp r2, #32
	blt word4_cp
	ldm r1!, {r4-r11}
	stm r0!, {r4-r11}
	sub r2, r2, #32
	b word8_cp
word4_cp:
	cmp r2, #16
	blt word2_cp
	ldm r1!, {r4-r7}
	stm r0!, {r4-r7}
	sub r2, r2, #16
	b word4_cp
word2_cp:
	cmp r2, #8
	blt word_cp
	ldm r1!, {r4-r5}
	stm r0!, {r4-r5}
	sub r2, r2, #8
	b word2_cp
word_cp:
	cmp r2, #0
	beq done
	ldr r4, [r1]
	str r4, [r0]
done:
	mov r0, r3
	pop {r4-r11}
	bx lr
ASM_FUNCTION_END(memcpy_4bytes_aligned)

#if defined(__IASMARM__) || defined(__ICCARM__)
    END
#endif
